<?php

class ad
{
    public static function get_ad($zone)
    {
        $scripts['trendx.info']['title'] =                  ad::get_AffiliateRobot($zone);
        $scripts['trendx.info']['left_box_1'] ="";//             ad::get_revenueHits('left_box_1'); //small box under poster
        $scripts['trendx.info']['left_bar_1'] ="";//             ad::get_techCPM('left_bar_1'); //skyscraper box under actors
        $scripts['trendx.info']['left_bar_2'] ="";//             ""; //second skyscraper box under actors
        $scripts['trendx.info']['center_banner_1'] =        ad::get_revenueHits('center_banner_1'); //main banner
        $scripts['trendx.info']['center_banner_2'] ="";//        ad::get_propeller('center_banner_1');//ad::get_technoratiMedia('center_banner_1'); //between trailer and downloads
        $scripts['trendx.info']['center_banner_3'] ="";//        ad::get_techCPM('center_banner_1');//ad::get_propeller('center_banner_1'); //after similar and before reviews
        $scripts['trendx.info']['on_download'] ="";//            "";////ad::put_in_container(ad::get_yllix('center_banner_1'), 'on_download'); //download button
        $scripts['trendx.info']['overlay_download'] ="";//       "";//ad::put_in_container(ad::get_yllix('center_banner_1'), 'overlay_download'); //hidden overlay on top of download links
        $scripts['trendx.info']['fake_download'] ="";//          ad::get_yllix('center_banner_1');//ad::put_in_container(ad::get_yllix('center_banner_1'), 'fake_download'); //hidden overlay on top of image right after the tabs
        $scripts['trendx.info']['small_banner_1'] =         ad::get_techCPM('small_banner_1');//
        $scripts['trendx.info']['small_banner_2'] =         ad::get_yllix('small_banner_1');//
        $scripts['trendx.info']['small_banner_3'] =         ad::get_CPMadserver('small_banner_1');
        $scripts['trendx.info']['small_banner_4'] =         ad::get_technoratiMedia('center_banner_1');

        $domain = ad::get_domain();

        return $scripts[$domain][$zone];
    }

    public static function put_in_container($script, $container)
    {
        $output = '';
        switch ($container)
        {
            case 'on_download': //creates a big download button with an invisible ad overlay on top of it
                ob_start(); ?>
                <div style="position: absolute; margin-top: 60px; opacity: 0.0; width: 728px; height: 90px; z-index: 300;">
                    <?=$script?>
                </div>
                <div id="download_btn"><img  alt="Click to Download" src="/res/img/download_btn.png" /></div>
                <?php $output = ob_get_clean();
                break;
            case 'overlay_download': //creates invisible div overlay with the ad inside it
                ob_start(); ?>
                <div style="position: absolute; margin-top:70px; opacity: 0.0; width: 728px; height: 90px; z-index: 300;">
                    <?=$script?>
                </div>
                <?php $output = ob_get_clean();
                break;
            case 'fake_download': //creates a standard leaderboard sized banner with download buttons image that is overlayed by the invisible ad banner
                ob_start(); ?>
                <div style="position: absolute; opacity: 0.0; width: 728px; height: 90px; z-index: 300;">
                    <?=$script?>
                </div>
                <img src="/res/img/banner.png" />
                <?php $output = ob_get_clean();
                break;
        }
        return $output;
    }

    private static function get_domain()
    {
        if($_SERVER['SERVER_NAME'] == 'localhost') //for local testing
            return 'udnfind.com';

        return str_replace('www.','',$_SERVER['SERVER_NAME']);
    }

    public static function get_revenueHits($zone)
    {
        $codes['trendx.info']['left_box_1'] =           'UDNWEB_1466_2';
        $codes['trendx.info']['center_banner_1'] =      'UDNWEB_1466_0';

        $codes['earnmovie.com']['left_box_1'] =         'UDNWEB_1798_0';
        $codes['earnmovie.com']['center_banner_1'] =    'UDNWEB_1798_1';

        $codes['getmovielinks.com']['left_box_1'] =     'UDNWEB_1799_0';
        $codes['getmovielinks.com']['center_banner_1'] ='UDNWEB_1799_1';

        $codes['moviezfind.com']['left_box_1'] =        'UDNWEB_1800_0';
        $codes['moviezfind.com']['center_banner_1'] =   'UDNWEB_1800_1';

        $codes['moviezhunt.com']['left_box_1'] =        'UDNWEB_1770_0';
        $codes['moviezhunt.com']['center_banner_1'] =   'UDNWEB_1770_1';

        $codes['ttmoviez.com']['left_box_1'] =          'UDNWEB_1801_0';
        $codes['ttmoviez.com']['center_banner_1'] =     'UDNWEB_1801_1';

        $codes['udnmovies.com']['left_box_1'] =          '';
        $codes['udnmovies.com']['center_banner_1'] =     '';



        $domain = ad::get_domain();
        $output = '';

        if($codes[$domain]) //make sure the domain has an entry above
            switch ($zone)
            {
                case 'left_box_1':
                    ob_start(); ?>
                    <!-- RevenueHits left_box_1-->
                    <script type="text/javascript">pb_cid='<?=$codes[$domain][$zone];?>';pb_type='banner_180x150';</script><script src="http://clkads.com/banners/script/include_img_banner.js" type="text/javascript"></script>
                    <?php $output = ob_get_clean();
                    break;
                case 'center_banner_1':
                    ob_start(); ?>
                    <!-- RevenueHits center_banner_1-->
                    <script type="text/javascript" src="http://clkrev.com/adServe/banners?tid=<?=$codes[$domain][$zone];?>&amp;size=728x90" ></script>
                    <?php $output = ob_get_clean();
                    break;
                case 'pop_under':
                    ob_start(); ?>
                    <script type="text/javascript" src="http://clkmon.com/adServe/banners?tid=UDNPP1"></script>
                    <?php $output = ob_get_clean();
                    break;
            }
        return $output;
    }

    public static function get_yllix($zone)
    {
        $codes['trendx.info']['center_banner_1'] =      '277524';
        $codes['earnmovie.com']['center_banner_1'] =    '277524';
        $codes['getmovielinks.com']['center_banner_1'] ='277524';
        $codes['moviezfind.com']['center_banner_1'] =   '277524';
        $codes['moviezhunt.com']['center_banner_1'] =   '277524';
        $codes['ttmoviez.com']['center_banner_1'] =     '277524';
        $codes['udnmovies.com']['center_banner_1'] =    '277524';

        $domain = ad::get_domain();
        $output = '';

        if($codes[$domain]) //make sure the domain has an entry above
            switch ($zone)
            {
                case 'center_banner_1':
                    ob_start(); ?>
                    <!-- yllix center_banner_1-->
                    <iframe src="http://yllix.com/banner_show.php?section=General&amp;pub=<?=$codes[$domain][$zone];?>&amp;format=728x90&amp;ga=g" frameborder="0" scrolling="no" width="728" height="90" marginwidth="0" marginheight="0"></iframe>
                    <?php $output = ob_get_clean();
                    break;
                case 'small_banner_1':
                    ob_start(); ?>
                    <iframe src="http://yllix.com/banner_show.php?section=General&amp;pub=277524&amp;format=468x60&amp;ga=g" frameborder="0" scrolling="no" width="468" height="60" marginwidth="0" marginheight="0"></iframe>
                    <?php $output = ob_get_clean();
                    break;
            }
        return $output;
    }

    private static function get_propeller($zone)
    {
        $codes['trendx.info']['center_banner_1'] = '277524'; //TODO:Find how different codes are assembled, now use satic below

        $domain = ad::get_domain();
        $output = '';

        if($codes[$domain]) //make sure the domain has an entry above
            switch ($zone)
            {
                case 'center_banner_1':
                    ob_start(); ?>
                    <iframe id='ad73a73f' name='ad73a73f' src='http://ad.propellerads.com/afr.php?zoneid=3170' frameborder='0' scrolling='no' width='728' height='90'><a href='http://ad.propellerads.com/ck.php?n=ad886a87' target='_blank'><img src='http://ad.propellerads.com/avw.php?zoneid=3170&n=ad886a87' border='0' alt='' /></a></iframe>
                    <?php $output = ob_get_clean();
                    break;
            }
        return $output;
    }

    private static function get_techCPM($zone)
    {
        $codes['trendx.info']['center_banner_1'] = '805/1696/1'; //TODO:Find how different codes are assembled, now use satic below
        $codes['trendx.info']['center_banner_1'] = '805/1696/3'; //TODO:Find how different codes are assembled, now use satic below

        $domain = ad::get_domain();
        $output = '';

        if($codes[$domain]) //make sure the domain has an entry above
            switch ($zone)
            {
                case 'center_banner_1':
                    ob_start(); ?>
                    <!-- TechCpm.Com Ad Code For http://trendx.info -->
                    <script src="http://ads.techcpm.com/techcpm/adscode/805/1696/1.js" type="text/javascript"></script>
                    <!-- Size: 728x90 -->
                    <?php $output = ob_get_clean();
                    break;
                case 'left_bar_1':
                    ob_start(); ?>
                    <!-- TechCpm.Com Ad Code For http://trendx.info -->
                    <script src="http://ads.techcpm.com/techcpm/adscode/805/1696/3.js" type="text/javascript"></script>
                    <!-- Size: 160x600 -->
                    <?php $output = ob_get_clean();
                    break;
                case 'small_banner_1':
                    ob_start(); ?>
                    <!-- TechCpm.Com Ad Code For http://trendx.info -->
                    <script src="http://ads.techcpm.com/techcpm/adscode/805/1696/4.js" type="text/javascript"></script>
                    <!-- Size: 468x60 -->
                    <?php $output = ob_get_clean();
                    break;
            }
        return $output;
    }

    private static function get_technoratiMedia($zone)
    {
        $codes['trendx.info']['center_banner_1'] = '805/1696/1'; //TODO:Find how different codes are assembled, now use satic below
        $codes['trendx.info']['left_bar_1'] = '805/1696/3'; //TODO:Find how different codes are assembled, now use satic below

        $domain = ad::get_domain();
        $output = '';

        if($codes[$domain]) //make sure the domain has an entry above
            switch ($zone)
            {
                case 'center_banner_1':
                    ob_start(); ?>
                    <!-- BEGIN TECHNORATI MEDIA TAG -->
                    <script type="text/javascript">
                        document.write('<scri' + 'pt type="text/javascript" src="'
                            + (document.location.protocol == 'https:' ? 'https://uat-secure' : 'http://ad-cdn')
                            + '.technoratimedia.com/00/20/98/uat_29820.js?ad_size=728x90"></scri' + 'pt>');
                    </script>
                    <!-- END TECHNORATI MEDIA TAG -->
                    <?php $output = ob_get_clean();
                    break;
                case 'left_bar_1':
                    ob_start(); ?>
                    <!-- BEGIN TECHNORATI MEDIA TAG -->
                    <script type="text/javascript">
                        document.write('<scri' + 'pt type="text/javascript" src="'
                            + (document.location.protocol == 'https:' ? 'https://uat-secure' : 'http://ad-cdn')
                            + '.technoratimedia.com/00/20/98/uat_29820.js?ad_size=160x600"></scri' + 'pt>');
                    </script>
                    <!-- END TECHNORATI MEDIA TAG -->
                    <?php $output = ob_get_clean();
                    break;
            }
        return $output;
    }

    private static function get_CPMadserver($zone)
    {
        $codes['trendx.info']['small_banner_1'] = '277524'; //TODO:Find how different codes are assembled, now use satic below

        $domain = ad::get_domain();
        $output = '';

        if($codes[$domain]) //make sure the domain has an entry above
            switch ($zone)
            {
                case 'center_banner_2':
                    ob_start(); ?>
                    <script language='JavaScript' type='text/javascript' src='http://www.cpmadserver.com/adx.js'></script>
                    <script language='JavaScript' type='text/javascript'>
                        <!--
                        if (!document.cpmAds_used) document.cpmAds_used = ',';
                        cpmAds_random = new String (Math.random()); cpmAds_random = cpmAds_random.substring(2,11);

                        document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
                        document.write ("http://www.cpmadserver.com/adjs.php?n=" + cpmAds_random);
                        document.write ("&amp;what=zone:45");
                        document.write ("&amp;exclude=" + document.cpmAds_used);
                        if (document.referrer)
                            document.write ("&amp;referer=" + escape(document.referrer));
                        document.write ("'><" + "/script>");
                        //-->
                    </script><noscript><a href='http://www.cpmadserver.com/adclick.php?n=a8b6dcb0' target='_blank'><img src='http://www.cpmadserver.com/adview.php?what=zone:45&amp;n=a8b6dcb0' border='0' alt=''></a></noscript>
                    <?php $output = ob_get_clean();
                    break;
            }
        return $output;
    }

    private static function get_AffiliateRobot($zone)
    {
        include('config.php');
        $codes['trendx.info']['title'] = ''; //TODO:Find how different codes are assembled, now use satic below

        $domain = ad::get_domain();
        $domain = 'trendx.info'; //forced override
        $output = '';

        if($codes[$domain]) //make sure the domain has an entry above
            switch ($zone)
            {
                case 'title':
                    ob_start(); ?>
                    <a href="https://cinaplay.com/pages/flowplayer?a_aid=51a4de24b6608&a_bid=72491354&chan=&pubid=&sid=&clickid=&subid=&g=030e5e6a3ad66c0c7f1c826a4beeef4a&&theme=lightgrey_no_banner">
                        <img src="/res/img/STREAM.gif" />
                    </a>
                    <?php $output = ob_get_clean();
                    break;
            }
        return $output;
    }

    public static function get_analytics()
    {
        $domain = ad::get_domain();

        $analytics['earnmovie.com'] =       'UA-39275700-1';
        $analytics['getmovielinks.com'] =   'UA-39268219-1';
        $analytics['moviezfind.com'] =      'UA-39276500-1';
        $analytics['moviezhunt.com'] =      'UA-39267121-1';
        $analytics['trendx.info'] =         'UA-36430534-1';
        $analytics['ttmoviez.com'] =        'UA-39270318-1';
        $analytics['udnmovies.com'] =       'UA-40854707-1';

        $analytics['udnfind.info'] =        'UA-41845141-2';

        $analytics['udnfind.com'] =         'UA-39783524-1';
        $analytics['apktake.com'] =         'UA-41302589-1';
        $analytics['findpatch.com'] =       'UA-41302589-2';
        $analytics['iostake.com'] =         'UA-41302589-3';
        $analytics['mactake.com'] =         'UA-41302589-4';
        $analytics['overwindows.com'] =     'UA-41302589-5';
        $analytics['pcgamefind.com'] =      'UA-41302589-6';
        $analytics['ps3find.com'] =         'UA-41302589-7';
        $analytics['udnbook.com'] =         'UA-41302589-8';
        $analytics['udnmobile.com'] =       'UA-41302589-9';
        $analytics['udnmusic.com'] =        'UA-41302589-10';
        $analytics['xboxall.com'] =         'UA-41302589-11';

        $output = '';
        ob_start(); ?>
    <script type="text/javascript">
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', '<?=$analytics[$domain]?>']);
        _gaq.push(['_trackPageview']);

        (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();
    </script>
    <?php $output = ob_get_clean();

        return $output;
    }


}